Home |
| Latest | About | Random
# Coding assignment for week 1 For each of these problems, write a piece of python code to solve it. Create a new python notebook and do your work there. You can separate out each problem in different cells. Organize your work. And submit your final python notebook onto Canvas. (You can download your python notebook after working on it from colab.google.research.com) You can do it! Work together! I will have office hours Monday at 4pm at Boelter where we have usual class to answer questions. (1) Find the sum of the first $100$ positive integer by code, that is find $1+2+...+100$ using a python code. (2) Find the sum of the first $10$ positive squares, $1^{2}+2^2+...+10^{2}$. Note to taking powers like $a^{b}$ we need to write ```a**b``` in python. (3) Consider the infinite series $\displaystyle\sum_{n=0}^{\infty} (-1)^{n}\frac{4}{2n+1}$. Estimate it using 100, 1000, and 10000 terms. Do you recognize this number? (4) Define the Fibonacci sequence $a_{n}$ to be $a_{0}=0$ and $a_{1}=1$, and that $a_{n+2}=a_{n+1}+a_{n}$, so that each term is the sum of the previous two. Write a piece of code to find $a_{2023}$. Careful with indexing. To help you troubleshoot, write out the first few terms of the Fibonacci sequence with their indexing, $a_{0}=0,a_{1}=1,a_{2}=1,a_{3}=?$ (5) Use the python ```str()``` function that converts a number to a string, and determine how many times the digit 0 shows up in the 2023th Fibonacci number $a_{2023}$. Then, find out how many times each digit shows up, so we have a frequency table. Which digit shows up the most? By the way, you can print a pair of things (or any tuples of things) by doing this ```print(variable1, variable2)```. (6) Write a piece of python code that prints the following pyramid, where on line $i$ there are $i^{2}$ many letter As. Make it so it can print however many lines we want: ``` A AAAA AAAAAAAAA AAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ```